package com.sharekitchen.utils;

import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import java.util.ArrayList;
import java.util.List;

public class gaodeAPI {
    public static String get(String address){
        try {
            // 替换成你的高德地图API Key
//            String apiKey = "07030115396a7f18744a1836e9e2b8d7";
//            String apiKey = "a1da374e8f6b019ec155741304641f99";
            String apiKey = "6c5b817b24bce82746c3c53c270c3892";
            // 地址
            // 构建URL
            String url = "https://restapi.amap.com/v3/geocode/geo?key="+apiKey+"&address="+address;
            CloseableHttpClient httpClient = HttpClients.createDefault();
            HttpGet request = new HttpGet(url);
            CloseableHttpResponse response = httpClient.execute(request);
            // 获取响应内容
            String result = EntityUtils.toString(response.getEntity());
            return result.split("location")[1].split("\"")[2];
            // 这里你需要解析返回的JSON以获取经纬度信息
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}
